﻿using log;
using Microsoft.CSharp;
using Microsoft.JScript;
using Microsoft.JScript.Vsa;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.Caching;
using System.Web.Services.Description;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
using YouDaoNotesCodes.CSharp_highLevel;
using YouDaoNotesCodes.JSON;
using YouDaoNotesCodes.JSON.JArray和JObject封装JSON对象;
using YouDaoNotesCodes.List;
using YouDaoNotesCodes.XML;

namespace YouDaoNotesCodes
{

    class Program
    {
        static void Main(string[] args)
        {
            //读取本地路径下的json
            //string path = AppDomain.CurrentDomain.BaseDirectory + "";//debug下
            //读取指定路径下的json
            string jsonfile = "E://lgceshi.json";

            //读取自定目录下的json文件
            StreamReader sr = new StreamReader(jsonfile);
            string json = sr.ReadToEnd();
            //Console.WriteLine(json)

            //XmlDocument doc = new XmlDocument();
            //doc.Load("E://LG_test.xml");//这样就可以

            try
            {
                //测试
                List<Receivable_list> newrevList = new List<Receivable_list>();
                List<Receivable_list> revList = JsonConvert.DeserializeObject<List<Receivable_list>>(json);
                Console.WriteLine(JsonConvert.SerializeObject(revList));

                if (revList.Count > 1 && (revList[0].receivable_id == revList[1].receivable_id))
                {
                    //JSON数组相同元素合并问题如何处理？暂时处理方式！
                    //revList.Clear();
                    newrevList.Add(new Receivable_list { receivable_id = revList[0].receivable_id, amount = 10000 });
                
                }
                Console.WriteLine(revList.Count);
                Console.WriteLine(revList[0].receivable_id);
                Console.WriteLine(revList[1].receivable_id);
                Console.WriteLine(JsonConvert.SerializeObject(newrevList));

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }
    }
    public struct Receivable_list
    {
        /// <summary>
        /// 应收账ID，NOT NULL
        /// </summary>
        [JsonProperty]
        public long receivable_id { get; set; }
        /// <summary>
        /// 应收账到账金额，NOT NULL
        /// </summary>
        [JsonProperty]
        public Decimal amount { get; set; }
    }
}

